package cn.hxzy.clientcrm;

import cn.hxzy.clientcrm.filter.ClientFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
public class ClientCrmApplication  extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(ClientCrmApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ClientCrmApplication.class);
    }

    @Value("${spring.application.name}")
    String applicationName;
    @Value("${server-url-prefix}")
    String serverUrl;



    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new ClientFilter());
        Map initParameters = new HashMap(2);
        initParameters.put("applicationName", applicationName);
        initParameters.put("serverUrl", serverUrl);
        registrationBean.setInitParameters(initParameters);
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }
}
